package com.darren.framework.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.darren.framework.dao.GenericDao;
import com.darren.framework.service.GenericService;

@Service
public abstract class GenericServiceImpl<T,PK extends Serializable> extends BaseServiceImpl implements GenericService<T,PK>{
	
	@Autowired
	protected GenericDao<T,PK> genericDao;
	
	@Override
	public T save(T entity){
		entity = genericDao.save(entity);
		return entity;	
	}
	
	@Override
	public T update(T entity){
		return genericDao.update(entity);
	}
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED, readOnly = true)
	public T findById(PK id){
		return genericDao.findById(id);
	}
	
	@Override
	public T delete(T entity){
		return genericDao.delete(entity);
	}
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED,rollbackFor=java.lang.Exception.class)
	public void deleteById(PK id){
		genericDao.deleteById(id);
	}
	
	@Override
	public List<T> getAll(){
		return genericDao.getAll();
	}
	
}
